import time
from loguru import logger
from api_func.account import login


def get_date():
    # 返回日期格式的字符串
    return time.strftime('%Y-%m-%d')


count = 0
def write_log(log_str, log_level='info'):
    global count
    # 写日志
    file_path = './Logs/' + get_date() + '.log'  # '../Logs/2024-07-17.log'
    if count == 0:
        logger.add(file_path)
        count += 1
    if log_level == 'info':
        logger.info(log_str)
    elif log_level == 'warning':
        logger.warning(log_str)
    elif log_level == 'debug':
        logger.debug(log_str)
    elif log_level == 'critical':
        logger.critical(log_str)


def get_token():
    response = login('19912312399')
    res_body = response.json()
    token = res_body['data']['token']
    return token


if __name__ == '__main__':
    # 测试自己写的代码全部写在这里，一个文件一个即可，没有调试代码，写个pass也行
    # pycharm提供了快捷键：main 回车即可
    write_log('info日志', 'info')
    write_log('warning日志', 'warning')
    write_log('debug日志', 'debug')
    write_log('critical日志', 'critical')